docs: extend CONTRIBUTING.md with code guidelines#4202
docs: extend CONTRIBUTING.md with code guidelines#4202jlaportebot wants to merge 1 commit intogoogle:masterfrom
Conversation
Add comprehensive section documenting common code patterns and conventions: - Naming conventions (files, receivers, types, methods, variables) - JSON tags for request bodies (required vs optional fields, omitzero) - URL tags for query parameters (non-pointer fields with omitempty) - Pagination patterns (ListOptions, ListCursorOptions, best practices) - Common types (ID, NodeID, Timestamp, boolean fields) - Generation patterns (accessors, iterators, documentation, linter rules) This addresses issue google#4023 and helps new contributors understand the codebase better, reducing review burden and improving code consistency.
gmlewis
left a comment
There was a problem hiding this comment.
Thank you, @jlaportebot.
LGTM.
cc: @alexandear
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4202 +/- ##
=======================================
Coverage 93.71% 93.71%
=======================================
Files 209 209
Lines 19772 19772
=======================================
Hits 18529 18529
Misses 1046 1046
Partials 197 197 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
alexandear
left a comment
There was a problem hiding this comment.
@jlaportebot Thank you. I left a few comments regarding excessive formatting and redundant information. Could you also review the entire CONTRIBUTING.md document and consolidate duplicated content?
Also, I think this PR should be reviewed by everyone listed in the REVIEWERS file.
|
|
||
| [Go Doc Comments]: https://go.dev/doc/comment | ||
|
|
||
| ## Code Guidelines |
There was a problem hiding this comment.
I think the "Code Comments" section above should be under "Code Guidelines".
| #### Generated Documentation | ||
|
|
||
| Documentation links are automatically generated from `openapi_operations.yaml`. | ||
| Run `script/generate.sh` to update these links. |
There was a problem hiding this comment.
These lines are not needed.
They are already in "Submitting a patch", "Metadata", and "Scripts".
Can be removed.
| #### Linter Rules | ||
|
|
||
| The repository uses custom linter rules to enforce consistency: | ||
| - `sliceofpointers` - Ensures slice fields use pointers | ||
| - `structfield` - Ensures struct fields follow naming conventions |
There was a problem hiding this comment.
We have more linters. Let's simply remove this section.
| State string `json:"state"` // Required field | ||
| // ... |
There was a problem hiding this comment.
Please use TABs instead of spaces for all examples:
| State string `json:"state"` // Required field | |
| // ... | |
| State string `json:"state"` // Required field | |
| // ... |
|
|
||
| ### Naming Conventions | ||
|
|
||
| #### File Names |
There was a problem hiding this comment.
Should we remove the "Other notes on code organization" section?
| #### Enterprise and Organization Scoped Methods | ||
|
|
||
| Methods that operate on enterprise or organization resources include the scope | ||
| in their name: | ||
|
|
||
| ```go | ||
| // Enterprise-scoped methods | ||
| func (s *EnterpriseService) GetLicenseInfo(ctx context.Context) (*LicenseInfo, *Response, error) | ||
|
|
||
| // Organization-scoped methods | ||
| func (s *OrganizationsService) ListMembers(ctx context.Context, org string, opts *OrganizationListMembersOptions) ([]*User, *Response, error) | ||
| ``` |
There was a problem hiding this comment.
Actually, I think this subsection may be incorrect - see #3761.
|
|
||
| When defining structs that represent a request body (sent via POST/PUT/PATCH): | ||
|
|
||
| 1. **Required fields** should be non-pointer types without `omitempty`: |
There was a problem hiding this comment.
Please do not use excessive LLM-like formatting:
| 1. **Required fields** should be non-pointer types without `omitempty`: | |
| 1. Required fields should be non-pointer types without `omitempty`: |
| 2. **Handle nil options** in your methods: | ||
|
|
||
| ```go | ||
| func (s *RepositoriesService) List(ctx context.Context, user string, opts *RepositoryListOptions) ([]*Repository, *Response, error) { | ||
| if opts == nil { | ||
| opts = &RepositoryListOptions{} | ||
| } | ||
| // ... | ||
| } | ||
| ``` |
There was a problem hiding this comment.
This can be removed. We have the addOptions to handle nil options.
Summary
This PR extends CONTRIBUTING.md with a comprehensive section on code guidelines and conventions, addressing issue #4023.
Changes
Added a new "Code Guidelines" section that documents:
Naming Conventions
JSON Tags for Request Bodies
URL Tags for Query Parameters
Pagination
Common Types
Generation Patterns
Benefits
Testing
This is a documentation-only change. No code changes or tests needed.
Closes #4023